package com.chinamoney.wppm.controller;

import java.util.Map;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.bind.annotation.RestController;

import com.chinamoney.wppm.entity.EleForm;
import com.chinamoney.wppm.service.EformService;
import com.chinamoney.wppm.util.ResultMessage;

/**
 * 
 * @author Jason_Jiang
 *
 */
@RestController
public class EleFormController {
	
	@Autowired
	private EformService eformService;
	
	@GetMapping("eform/{id}")
	public ResultMessage<EleForm> getEformById(@PathVariable("id") String id) {
		return eformService.getEformById(id);
	}
	
	/**
	 * 获取预算花费情况（根据电子需求单的工作量评估进行计算）
	 * @param budgetFrom
	 * @param statelabels
	 * @return
	 */
	@RequestMapping(value="eform/cost/{budgetFrom}", method = RequestMethod.GET)
	public ResultMessage<?> getBdmCostByStatelabel(@PathVariable("budgetFrom") String budgetFrom,  String type) {
		String statelabels = "";
		if("1".equals(type)) {
			statelabels = "实施;结束";
		}
		return eformService.getBdmCostByStatelabel(budgetFrom, statelabels); 
	}
	
	
	/**
	 * 获取预算花费明细
	 * @param budgetFrom
	 * @param statelabels
	 * @return
	 */
	@GetMapping("eform/list/bdm/{budgetFrom}")
	public ResultMessage<?> getEformsByBdm(@PathVariable("budgetFrom") String budgetFrom, String type) {
		String statelabels = "";
		if("1".equals(type)) {
			statelabels = "实施;结束";
		}
		return eformService.getEformsByBdm(budgetFrom, statelabels);
	}

	/**
	 * 获取 时间点-创建数量 折线图
	 * @param rows
	 * @return
	 */
	@ResponseBody
	@GetMapping(value = "/eform/echart")
	public  Map<String, Object> getEforms(Integer rows) {
		return eformService.createCharts(rows);
	}
	
	/**
	 * 获取电子需求单列表
	 * @param code
	 * @param businessName
	 * @param stateNow
	 * @param limit
	 * @param offset
	 * @return
	 */
	@ResponseBody
	@GetMapping("eform/list")
	public Map<String, Object> getEleForms(
			@RequestParam(value = "code", required = false, defaultValue = "") String code,
			@RequestParam(value = "businessName", required = false, defaultValue = "") String businessName,
			@RequestParam(value = "stateNow", required = false, defaultValue = "") String stateNow
			, Integer limit, Integer offset) {
		return eformService.getEleForms(code, businessName, stateNow, limit, offset);
	}
	
}
